package com.yanqu.road.server.cmd.estatewar;

import com.yanqu.road.pb.estatewar.EstateWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.EstateWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_ESTATE_WAR_BATTLE, desc = "抢夺矿坑")
public class EstateWarBattleCmd extends AbstractCommand {

	private int type;

	private int pos;

	private long enemyServerId;

	private long enemyUserId;

	private int nextType;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		EstateWarProto.EstateWarBattleReqMsg reqMsg = EstateWarProto.EstateWarBattleReqMsg.parseFrom(packet.getBytes());
		type = reqMsg.getType();
		pos = reqMsg.getPos();
		enemyServerId = reqMsg.getEnemyServerId();
		enemyUserId = reqMsg.getEnemyUserId();
		if(reqMsg.hasNextType()){
			nextType = reqMsg.getNextType();
		}
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		long nowTime = System.currentTimeMillis();
		player.sendPacket(Protocol.U_ESTATE_WAR_BATTLE, EstateWarMgr.estateBattle(player, type, pos, enemyServerId, enemyUserId, nextType));
		log.info("estate battle cost time:{}", System.currentTimeMillis() - nowTime);
	}

	@Override
	public void sendData(GamePlayer player) {

	}
}
